home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 41.zip
/
BS1 part 41
/
vga utildisk 5.adf
/
m.doc
< prev
next >
Wrap
Text File
|
1988-01-19
|
2KB
|
35 lines
ABSTRACT: The two C files 'producer.c' and 'consumer.c' demonstrate multitasking
on the Amiga.
In the 'real' world the producer/consumer problem is a classical one. It neatly
depicts the problem of two processes (tasks) communicating with each other.
Imagine a warehouse where a continuous stream of products is delivered by a
large truck (the producer). The customers (consumers) of this warehouse have
small trucks in which they collect there goodies. For simplicity let's limit the
number of consumers to one. Now the warehouse happens to have a small parking
place where only one truck at a time (the large one or the small one) can park.
To keep the producer and the consumer satisfied the warehouse will allow them to
park alternatively so the stock doesn't only increase or decrease.
Let's translate the problem to software: Of course the producer and consumer
are two separate tasks. The parking place is a message port. The producer
will deliver an item to the message port (a number) and assuming the stock
is full will wait for the consumer to consume the item (just read it). The
consumer will then return an item (another number).
The two C programs simulate the above decribed problem. Of course one of
the tasks has to do all initializations, I decided that the producer should
do this. So the core is really small.
Compile each file and run the producer and consumer each in it's own window
(start with producer). The producer will send 50 numbers to the consumer by
means of the messages mechanism.
I hope these two little programs make the message mechanism on the Amiga more
familiar to you.
Joost Boerhout
Waterigeweg 50
3703 CP Zeist
the Netherlands